package com.intech.android.demo.cms.beans;

import com.intech.android.demo.cms.common.Constants;
import com.intech.android.demo.cms.common.FacesHelper;
import com.intech.android.demo.cms.common.Util;
import com.intech.android.demo.cms.decorators.FeedbackDecorator;

import java.util.ArrayList;
import java.util.List;

public class FeedbackBean
{
    private String messageId;
    private String MSISDN;
    private String choosedNotification;
    private List<String> notificationList;
    private String question;
    private String answer;
    private List<FeedbackDecorator> feedbackDecorators;

    public FeedbackBean()
    {
        notificationList = new ArrayList<String>();
        notificationList.add("Yes");
        notificationList.add("No");
        if (Util.isEmpty(feedbackDecorators))
        {
            fillRegionListTempValues();
        }
    }

    private void fillRegionListTempValues()
    {
        feedbackDecorators = new ArrayList<FeedbackDecorator>();
        feedbackDecorators.add(new FeedbackDecorator("1", "9111111111", "I ask...", "Yes", "Yes", "We answer..."));
        feedbackDecorators.add(new FeedbackDecorator("2", "9122222222", "I ask...", "No", "Yes", "We answer..."));
        feedbackDecorators.add(new FeedbackDecorator("3", "9133333333", "I ask...", "No", "Yes", "We answer..."));
        feedbackDecorators.add(new FeedbackDecorator("4", "9144444444", "I ask...", "Yes", "No", "We answer..."));
    }

    public String toFeedback()
    {
        return Constants.Navigation.FEEDBACK_LINK;
    }

    public String saveEditedAnswer()
    {
        for (FeedbackDecorator feedbackDecorator : feedbackDecorators)
        {
            if (feedbackDecorator.getMesID() == Integer.parseInt(messageId))
            {
                feedbackDecorator.setAnswer(answer);
            }
        }
        return Constants.Navigation.FEEDBACK_LINK;
    }

    public String editAnswer()
    {

        Integer bannerId = FacesHelper.getParameterAsInteger("edit_answer");
        if (bannerId == null)
        {
            return Constants.Navigation.FEEDBACK_LINK;
        }

        FeedbackDecorator currentDecorator = new FeedbackDecorator();
        for (FeedbackDecorator feedbackDecorator : feedbackDecorators)
        {
            if (feedbackDecorator.getMesID().equals(bannerId))
            {
                currentDecorator = feedbackDecorator;
            }
        }
        messageId = currentDecorator.getMesID().toString();
        MSISDN = currentDecorator.getMSISDN();
        choosedNotification = currentDecorator.getNotification();
        question = currentDecorator.getQuestion();
        answer = currentDecorator.getAnswer();
        return Constants.Navigation.FEEDBACK_QUESTION_LINK;
    }

    public List<FeedbackDecorator> getFeedbackDecorators()
    {
        return feedbackDecorators;
    }

    public void setFeedbackDecorators(List<FeedbackDecorator> feedbackDecorators)
    {
        this.feedbackDecorators = feedbackDecorators;
    }

    public String getAnswer()
    {
        return answer;
    }

    public void setAnswer(String answer)
    {
        this.answer = answer;
    }

    public String getQuestion()
    {

        return question;
    }

    public void setQuestion(String question)
    {
        this.question = question;
    }

    public List<String> getNotificationList()
    {

        return notificationList;
    }

    public void setNotificationList(List<String> notificationList)
    {
        this.notificationList = notificationList;
    }

    public String getChoosedNotification()
    {

        return choosedNotification;
    }

    public void setChoosedNotification(String choosedNotification)
    {
        this.choosedNotification = choosedNotification;
    }

    public String getMSISDN()
    {

        return MSISDN;
    }

    public void setMSISDN(String MSISDN)
    {
        this.MSISDN = MSISDN;
    }

    public String getMessageId()
    {
        return messageId;
    }

    public void setMessageId(String messageId)
    {
        this.messageId = messageId;
    }
}
